

using System.Collections.ObjectModel;

using Bee.Base.Abstractions.Tasks;
using Bee.Base.Models;
using Bee.Base.Models.Tasks;
using Bee.Base.ViewModels;

using CommunityToolkit.Mvvm.ComponentModel;

namespace Bee.Plugin.Multimedia.ViewModels;

public partial class MultimediaViewModelBase<T> : ObservableObject where T : TaskArgumentBase, new()
{
    /// <summary>
    /// 可选的输入图片格式集合
    /// </summary>
    private ObservableCollection<SelectableItem> _availableInputFormats = [];

    public ObservableCollection<SelectableItem> AvailableInputFormats
    {
        get => _availableInputFormats;
        private set
        {
            TaskList.SetInputExtensions(value.Where(x => x.IsSelected).Select(x => x.Label));
            SetProperty(ref _availableInputFormats, value);
        }
    }

    /// <summary>
    /// 任务列表控件视图模型
    /// </summary>
    public ITaskListViewModel<T> TaskList { get; }

    public MultimediaViewModelBase(TaskListViewModel<T> taskList, IEnumerable<string>? inputExtensions = null, bool enableConfigure = false)
    {
        TaskList = taskList;
        // 初始化任务参数
        TaskList.InitialArguments(MultimediaProcessConsts.PluginName);
        // 设置任务列表初始可选择的文件类型
        //TaskList.SetInputExtensions(inputExtensions);
        // 启用任务配置
        if (enableConfigure)
        {
            TaskList.EnableConfigure();
        }

        AvailableInputFormats = inputExtensions != null ?
            [.. inputExtensions.Select(x => new SelectableItem { Label = x, IsSelected = true })] :
            []
            ;
    }
}